
{extend name='admin@main'}

{block name="content"}

<script>
layui.use('upload', function(){
  var $ = layui.jquery
  ,upload = layui.upload;
  
  //普通图片上传
  var uploadInst = upload.render({
    elem: '#test1'
    ,url: '/upload/'
    ,before: function(obj){
      //预读本地文件示例，不支持ie8
      obj.preview(function(index, file, result){
        $('#demo1').attr('src', result); //图片链接（base64）
      });
    }
    ,done: function(res){
      //如果上传失败
      if(res.code > 0){
        return layer.msg('上传失败');
      }
      //上传成功
    }
    ,error: function(){
      //演示失败状态，并实现重传
      var demoText = $('#demoText');
      demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
      demoText.find('.demo-reload').on('click', function(){
        uploadInst.upload();
      });
    }
  });
  
  //多图片上传
  upload.render({
    elem: '#test2'
    ,url: '/upload/'
    ,multiple: true
    ,before: function(obj){
      //预读本地文件示例，不支持ie8
      obj.preview(function(index, file, result){
        $('#demo2').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
      });
    }
    ,done: function(res){
      //上传完毕
    }
  });
  
  //指定允许上传的文件类型
  upload.render({
    elem: '#test3'
    ,url: '/upload/'
    ,accept: 'file' //普通文件
    ,done: function(res){
      console.log(res)
    }
  });
  upload.render({ //允许上传的文件后缀
    elem: '#test4'
    ,url: '/upload/'
    ,accept: 'file' //普通文件
    ,exts: 'zip|rar|7z' //只允许上传压缩文件
    ,done: function(res){
      console.log(res)
    }
  });
  upload.render({
    elem: '#test5'
    ,url: '/upload/'
    ,accept: 'video' //视频
    ,done: function(res){
      console.log(res)
    }
  });
  upload.render({
    elem: '#test6'
    ,url: '/upload/'
    ,accept: 'audio' //音频
    ,done: function(res){
      console.log(res)
    }
  });
  
  //设定文件大小限制
  upload.render({
    elem: '#test7'
    ,url: '/upload/'
    ,size: 60 //限制文件大小，单位 KB
    ,done: function(res){
      console.log(res)
    }
  });
  
  //同时绑定多个元素，并将属性设定在元素上
  upload.render({
    elem: '.demoMore'
    ,before: function(){
      layer.tips('接口地址：'+ this.url, this.item, {tips: 1});
    }
    ,done: function(res, index, upload){
      var item = this.item;
      console.log(item); //获取当前触发上传的元素，layui 2.1.0 新增
    }
  })
  
  //选完文件后不自动上传
  upload.render({
    elem: '#test8'
    ,url: '/upload/'
    ,auto: false
    //,multiple: true
    ,bindAction: '#test9'
    ,done: function(res){
      console.log(res)
    }
  });
  
  //拖拽上传
  upload.render({
    elem: '#test10'
    ,url: '/upload/'
    ,done: function(res){
      console.log(res)
    }
  });
  
	//多文件列表示例
	var demoListView = $('#demoList'),
	uploadListIns = upload.render({
		elem: '#testList',
		url: '{:url("upload")}',
		accept: 'file',
		multiple: true,
		auto: false,
		bindAction: '#testListAction',
		choose: function(obj) {
			var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
			//读取本地文件
			obj.preview(function(index, file, result) {
			
				//console.log(index);
				
				var tr = $(['<tr id="upload-' + index + '">', '<td>' + file.name + '</td>', '<td>' + (file.size / 1014).toFixed(1) + 'kb</td>', '<td>等待上传</td>', '<td>', '<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>', '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>', '</td>', '</tr>'].join(''));

				//单个重传
				tr.find('.demo-reload').on('click',
				function() {
					obj.upload(index, file);
				});

				//删除
				tr.find('.demo-delete').on('click',
				function() {
					delete files[index]; //删除对应的文件
					tr.remove();
					uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
				});

				demoListView.append(tr);
			});
		},
		done: function(res, index, upload) {
			console.log(res);
			
			
			//console.log(upload);
			if (res.code == 0) { //上传成功
				var tr = demoListView.find('tr#upload-' + index),
				tds = tr.children();
				var str ='<input type="hidden" name="fileurl[]" value="'+res.url+'"><input type="hidden" name="user_id[]" value="'+res.user_id+'">';
				str +='<input type="hidden" name="original_name[]" value="'+res.original_name+'"><input type="hidden" name="fileext[]" value="'+res.extension+'">';
				str +='<input type="hidden" name="filesize[]" value="'+res.size+'"><input type="hidden" name="filename[]" value="'+res.save_name+'">';
				str +='<input type="hidden" name="md5code[]" value="'+res.md5+'"><input type="hidden" name="sha1code[]" value="'+res.sha1+'">';
				
				tds.eq(2).html('<span style="color: #5FB878;">上传成功'+str+'</span>');
				tds.eq(3).html('<a href="'+res.url+'" target="new">查看</a>'); //清空操作
				return delete this.files[index]; //删除文件队列已经上传成功的文件
			}
			this.error(index, upload);
		},
		error: function(index, upload) {
			var tr = demoListView.find('tr#upload-' + index),
			tds = tr.children();
			tds.eq(2).html('<span style="color: #FF5722;">上传失败</span>');
			tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
		}
	});
  
  //绑定原始文件域
  upload.render({
    elem: '#test20'
    ,url: '/upload/'
    ,done: function(res){
      console.log(res)
    }
  });
  
});
</script>





<form class="layui-form layui-card" action="{:request()->url()}" data-auto="true" method="post" autocomplete="off">



<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
  <ul class="layui-tab-title">
    <li class="layui-this">基本信息</li>
    <li>办理流程</li>
  </ul>


<div class="layui-tab-content"><!--tab out-->
    <div class="layui-tab-item layui-show"><!--tab1-->
		<div class="layui-card-body think-box-shadow padding-left-40">
	        <div class="layui-form-item">
	            <label class="layui-form-label label-required">文件标题</label>
	            <div class="layui-input-block">
	                <input name="title" value='{$vo.title|default=""}' required placeholder="请输入文件标题" class="layui-input">
	            </div>
	        </div>

	        <div class="layui-form-item nowrap">
	            <label class="layui-form-label label-required">发文编号</label>
	            <div class="layui-input-inline margin-right-0" style="width:120px">
	                <input name="docno" value='{$vo.docno|default=""}' required placeholder="请输入发文编号" class="layui-input">
	            </div>
				

	            <label class="layui-form-label">拟 稿 人</label>
	            <div class="layui-input-inline margin-right-0" style="width:120px">
	                <input type="text" name="docauthor" value='{$vo.docauthor|default=""}'  placeholder="" class="layui-input" >
	            </div>
				
	            <label class="layui-form-label">拟稿部门</label>
	            <div class="layui-input-inline margin-right-0" style="width:120px">
	                <input type="text" name="docdept" value='{$vo.docdept|default=""}'  placeholder="" class="layui-input" >
	            </div>
				
	        </div>
			
			
	        <div class="layui-form-item nowrap">

	            <label class="layui-form-label label-required">拟稿日期</label>
	            <div class="layui-input-inline margin-right-0" style="width:120px">
	                <input type="text" data-date-input="date" name="docdate" value='{$vo.docdate|default=""}' required placeholder="拟稿日期" class="layui-input" >
	            </div>
				
				
	            <label class="layui-form-label ">紧急程度</label>
	            <div class="layui-input-inline margin-right-0" style="width:120px">
				  <select name="jinji" lay-verify="required">
				  {notempty name='vo.id'}<option selected value="{$vo.jinji}">{$vo.jinji}</option>{/notempty}
					<option value=""></option>
					
					<option value="平件">平件</option>
					<option value="紧急">紧急</option>
					<option value="加急">加急</option>

				  </select>
	            </div>
				
	            <label class="layui-form-label ">文件密级</label>
	            <div class="layui-input-inline margin-right-0" style="width:120px">
				  <select name="classes" lay-verify="required">
					
					{notempty name='vo.id'}<option selected value="{$vo.classes}">{$vo.classes}</option>{/notempty}
					<option value=""></option>

					<option value="公开">公开</option>
					<option value="不公开">不公开</option>
					<option value="保密">保密</option>
					<option value="绝密">绝密</option>

				  </select>
	            </div>
				
	        </div>
			
			
	        <div class="layui-form-item">
	            <label class="layui-form-label label-required">主送单位</label>
	            <div class="layui-input-block">
	                <input name="tounit1" value='{$vo.tounit1|default=""}' required placeholder="请输入主送单位" class="layui-input">
	            </div>
	        </div>
			
	        <div class="layui-form-item">
	            <label class="layui-form-label ">抄送单位</label>
	            <div class="layui-input-block">
	                <input name="tounit2" value='{$vo.tounit2|default=""}'  placeholder="请输入抄送单位" class="layui-input">
	            </div>
	        </div>
			


			<script src="/static/plugs/select/xm-select.js"></script>
			<script>
				var keshifuzeren = xmSelect.render({
					el: '#keshifuzeren', 
					name: 'keshifuzeren',
					toolbar: {
						show: true,
						list: [ 'ALL', 'CLEAR', 'REVERSE' ]
					},

					theme: {
						color: '#0081ff',
					},			
					paging: true,
					pageSize: 10,
					max:2,
					filterable: true,
					data: [
						{$str}
					]
				})	
			
			
				var shouwenwenyuan = xmSelect.render({
					el: '#shouwenwenyuan', 
					name: 'shouwenwenyuan',
					toolbar: {
						show: true,
						list: [ 'ALL', 'CLEAR', 'REVERSE' ]
					},
					paging: true,
					pageSize: 10,
					filterable: true,
					theme: {
						color: '#e54d42',
					},
					model: {
						label: {
							type: 'block',
							block: {
								//最大显示数量, 0:不限制
								showCount: 3,
								//是否显示删除图标
								showIcon: true,
							}
						}
					},
					max: 2,
					data: [
						{$str}
					]
				})	
			
			
				var bangongshizhuren = xmSelect.render({
					el: '#bangongshizhuren', 
					filterable: true,
					name: 'bangongshizhuren',
					paging: true,
					pageSize: 10,
					toolbar: {
						//show: true,
						//list: [ 'ALL', 'CLEAR', 'REVERSE' ]
					},
					theme: {
						color: '#f37b1d',
					},

					radio: true,
					data: [
						{$str}
					]
				})
			
				var fenguanlingdao = xmSelect.render({
					el: '#fenguanlingdao', 
					filterable: true,
					name: 'fenguanlingdao',
					paging: true,
					pageSize: 10,
					toolbar: {
						show: true,
						list: [ 'ALL', 'CLEAR', 'REVERSE' ]
					},
					theme: {
						color: '#8dc63f',
					},
					model: {
						label: {
							type: 'block',
							block: {
								//最大显示数量, 0:不限制
								showCount: 3,
								//是否显示删除图标
								showIcon: true,
							}
						}
					},
					data: [
						{$str}
					]
				})
			
				/*
				var zhuyaolingdao = xmSelect.render({
					el: '#zhuyaolingdao', 
					paging: true,
					pageSize: 10,
					filterable: true,
					name: 'zhuyaolingdao',
					toolbar: {
						show: true,
						list: [ 'ALL', 'CLEAR', 'REVERSE' ]
					},
					theme: {
						color: '#6739b6',
					},
					model: {
						label: {
							type: 'block',
							block: {
								//最大显示数量, 0:不限制
								showCount: 3,
								//是否显示删除图标
								showIcon: true,
							}
						}
					},
					data: [
						{$str}
					]
				})
				*/
			
			{if isset($vo) }
			keshifuzeren.setValue([ {$keshifuzeren} ])
			
			shouwenwenyuan.setValue([ {$shouwenwenyuan} ])
			
			bangongshizhuren.setValue([ {$bangongshizhuren} ])
			
			fenguanlingdao.setValue([ {$fenguanlingdao} ])
			
			//zhuyaolingdao.setValue([ { $zhuyaolingdao } ])
			{/if}
			</script>

			

	        <div class="layui-form-item">
	            <label class="layui-form-label label-required">科室/项目负责人</label>
	            <div class="layui-input-block">
	                <div id="keshifuzeren" class="xm-select-demo"></div>
	            </div>
	        </div>
			
	        <div class="layui-form-item">
	            <label class="layui-form-label ">办公室主任</label>
	            <div class="layui-input-block">
					<div id="bangongshizhuren" class="xm-select-demo"></div>
	            </div>
	        </div>


	        <div class="layui-form-item">
	            <label class="layui-form-label ">分管领导</label>
	            <div class="layui-input-block">
					<div id="fenguanlingdao" class="xm-select-demo"></div>
	            </div>
	        </div>
			
			<!--
	        <div class="layui-form-item">
	            <label class="layui-form-label ">主要领导</label>
	            <div class="layui-input-block">
					<div id="zhuyaolingdao" class="xm-select-demo"></div>
	            </div>
	        </div>-->

			
	        <div class="layui-form-item">
	            <label class="layui-form-label ">收发文员</label>
	            <div class="layui-input-block">
					<div id="shouwenwenyuan" class="xm-select-demo"></div>
	            </div>
	        </div>


			
	        <div class="layui-form-item">
	            <label class="layui-form-label ">文件列表</label>
	            <div class="layui-input-block">
	                <div class="layui-textarea padding-bottom-10" style="min-height:auto">
						<div class="layui-upload">
						  {if auth("edit") && request()->action() =='edit'  && $vo['docauthor']==session('admin_user')['nickname'] && $vo['status']!=2 }
						  <button type="button" class="layui-btn layui-btn-normal" id="testList">选择多文件</button> &nbsp;&nbsp;
						  <button type="button" class="layui-btn" id="testListAction">开始上传</button>
						  {/if}
						  
						  {if auth("add") && request()->action() =='add'  }
						  <button type="button" class="layui-btn layui-btn-normal" id="testList">选择多文件</button> &nbsp;&nbsp;
						  <button type="button" class="layui-btn" id="testListAction">开始上传</button>
						  {/if}	

						  <div class="layui-upload-list">
							<table class="layui-table">
							  <thead>
								<tr><th>文件名</th>
								<th>大小</th>
								<th>状态</th>
								<th>操作</th>
							  </tr></thead>
							  <tbody id="demoList">
							  {foreach $files as $key=>$vo}
							  <tr id="upload-{$vo.fileid}"><td>{$vo.original_name}</td><td>{$vo.filesize|format_size}</td><td></td>

								<td> <a target="new" href="{$vo.fileurl}">查看</a></td>


							  	  <tr>
							  {/foreach}
							  </tbody>
							</table>
						  </div>
						  
						</div> 


	                </div>
	            </div>
	        </div>
			

			
			{if request()->action() =='edit'}
	        <div class="layui-form-item">
	            <label class="layui-form-label ">批示情况</label>
	            <div class="layui-input-block">
	                <div class="layui-textarea padding-bottom-10" style="min-height:auto">

							<table class="layui-table">
							  <thead>
								<tr>
								<th>批示人</th>
								<th>批示时间</th>
								<th>批示类型</th>
								<th width="40%">批示内容</th>
							  </tr></thead>
							  {foreach $list_flow as $key=>$vo}
							  <tr id="upload-{$vo.id}">
							  <td>{$vo.username}</td>
							  <td>{$vo.addtime|format_datetime='Y-m-d H:i'}</td>
							  
							  <td>                
							  {eq name='vo.types' value='nigao'}<span class="layui-bg-red">拟稿完成</span>{/eq}
							  {eq name='vo.types' value='keshifuzeren'}<span class="layui-bg-orange">科室/项目负责人审核</span>{/eq}
							  {eq name='vo.types' value='shouwenwenyuan'}<span class="layui-bg-green">发文文员/拟稿人重核</span>{/eq}
							  {eq name='vo.types' value='bangongshizhuren'}<span class="layui-bg-blue">办公室主任</span>{/eq}
							  {eq name='vo.types' value='fenguanlingdao'}<span class="layui-bg-black">分管领导</span>{/eq}
							  {eq name='vo.types' value='zhuyaolingdao'}<span class="layui-bg-gray">主要领导</span>{/eq}
							  </td>
							  
							  <td> {$vo.info}</td>  <tr>
							  {/foreach}
							</table>

	                </div>
	            </div>
	        </div>
			{/if}
			
			
			
			
			{if request()->action() =='edit' && $rs_flow >0 && $my_flow_count ==0 }
	        <div class="layui-form-item">
	            <label class="layui-form-label">填写意见</label>
	            <div class="layui-input-block">

					<textarea class="layui-textarea" name="info" id="info" placeholder="请填写批示意见">{$info|default=""}</textarea>

	            </div>
				
	        </div>
			{/if}
	    </div>



	    <div class="hr-line-dashed"></div>
	    {notempty name='id'}<input type='hidden' value='{$id}' name='id' id="id">{/notempty}
		<input type='hidden' value='{$docauthor}' name='docauthor'>
	    <div class="layui-form-item text-center">
			{if request()->action() =='edit' && $rs_flow >0 && $my_flow_count ==0 }
			<button class="layui-btn" type='button' id="saveinfo">保存批示意见</button>
			{/if}
			
			{if request()->action() =='edit' && $docauthor == session('admin_user.nickname')  }
	        <button class="layui-btn" type='submit'>流转文件</button>
			{/if}
			{if request()->action() =='add' }
			<button class="layui-btn" type='submit'>保存数据</button>
			{/if}
	        <!-- <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要关闭吗？" data-close>关闭</button> data-modal-->
			<button class="layui-btn layui-btn-danger" onclick="hsitoryBack()" type="button">关闭</button>
	    </div>

	    <script>    
		window.form.render();
		function hsitoryBack(){
			$.msg.confirm('确定要关闭吗？', function (index) {
				history.back(), $.msg.close(index);
			});
		};
		
		
		</script>

	    
	</div><!--tab1-->

    <div class="layui-tab-item"><!--tab2-->
		<div class="layui-card-body think-box-shadow padding-left-40">


	        
		</div>
    </div><!--tab2-->
</div><!--tab out-->














</form>

<script>
    layui.use(['layer','form' ,'jquery'], function() {
        var layer = layui.layer, $ = layui.jquery ,form = layui.form;
        form.render();
    });
	

	$('#saveinfo').click(function(){
		var info = $("#info").val();
		var docid =$("#id").val();
		if (typeof(info) == "undefined")
		{
			layer.msg('数据错误!',{icon: 5});//失败的表情
			return ;
		}
		
		if(info == ''){
			layer.msg('请填写批示意见!',{icon: 5});//失败的表情
			return ;		
		}
		
		
		var url = "/document/docout/saveinfo.html";
		$.ajax({
			url:url,
			type:'post',
			data:'info='+info+'&docid='+docid,
			beforeSend:function () {
				
				this.layerIndex = layer.load(0, { shade: [0.5, '#393D49'] });
			},
			success:function(data){
				if(data.status == 'error'){
					layer.msg(data.msg,{icon: 5});//失败的表情
					return;
				}else if(data.status == 'success'){
					//layer.msg(data.msg,{icon: 6});
					layer.msg(data.msg, {
						icon: 6,//成功的表情
						time: 2000 //1秒关闭（如果不配置，默认是3秒）
					}, function(){
						//location.reload();
						window.location.href="/admin.html#/document/docnone/index.html?spm=m-66-70-71";
					});
				}
			},
			complete: function () {
				layer.close(this.layerIndex);
			},
		});
		return false;//阻止表单跳转
	});

</script>


{/block}